#include "welcomewindow.h"
#include <QApplication>
#include <QFont>

WelcomeWindow::WelcomeWindow(QWidget *parent)
    : QWidget(parent)
{
    // 设置窗口大小
    setFixedSize(300, 300);

    // 创建界面元素
    titleLabel = new QLabel("MyPuzzle");
    startButton = new QPushButton("Start Game");
    difficultyComboBox = new QComboBox();


    difficultyComboBox->addItem("3x3 简单", 3);
    difficultyComboBox->addItem("4x4 中等", 4);
    difficultyComboBox->addItem("5x5 困难", 5);

    difficultyComboBox->setStyleSheet(
        "QComboBox {"
        "  font-size: 14px;"
        "  padding: 5px;"
        "}");

    // 设置样式
    QFont titleFont("Arial", 24, QFont::Bold);
    titleLabel->setFont(titleFont);
    titleLabel->setAlignment(Qt::AlignCenter);

    startButton->setFixedSize(150, 40);
    startButton->setStyleSheet(
        "QPushButton {"
        "  background-color: #4CAF50;"
        "  border: none;"
        "  color: white;"
        "  font-size: 16px;"
        "  border-radius: 5px;"
        "}"
        "QPushButton:hover {"
        "  background-color: #45a049;"
        "}");

    // 布局管理

    QVBoxLayout *layout = new QVBoxLayout(this);
    layout->addStretch();
    layout->addWidget(titleLabel);
    layout->addSpacing(20);
    layout->addWidget(difficultyComboBox, 0, Qt::AlignCenter);
    layout->addSpacing(20);
    layout->addWidget(startButton, 0, Qt::AlignCenter);
    layout->addStretch();

    connect(startButton, &QPushButton::clicked, this, [this](){
        emit startClicked(this->geometry(), difficultyComboBox->currentData().toInt());  // 传递当前几何信息和难度
        this->hide();
    });

    // 添加难度改变信号
    connect(difficultyComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this](){
        emit difficultyChanged(difficultyComboBox->currentData().toInt());
    });


}

